<template>
    <div class="login">
      <div class="zhuce"><span @click="register">返回</span><span style="font-size:20px ;">注册</span></div>
        <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="userpwd"
        type="password"
        name="userpwd"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px">
      <van-button round block type="primary" native-type="submit"> 提交 </van-button>
    </div>
  </van-form>
    </div>
 
</template>
<script setup lang="ts">
import {useRouter} from "vue-router"
import { ref } from 'vue';
import {userRegister} from "../service/userService"
import { showSuccessToast} from 'vant';

interface ILoginApi{
  username:string;
  userpwd:string;
}

const router=useRouter()
const username = ref('')
const userpwd = ref('')
const onSubmit = (values: ILoginApi) => {
  console.log(values);
  
  loginreq(values);
}
let loginreq=async(data:ILoginApi)=>{
    let res=await userRegister(data)
    if(res.data.code==200){
      showSuccessToast("注册成功");
      //进行跳转到登录页
      router.push("/login");
    }
  }

const register=()=>{
  router.push("/login")
}
</script>

<style scoped lang="scss">
.login{
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  background: url("https://img2.baidu.com/it/u=2250997377,313757253&fm=253&fmt=auto&app=138&f=JPEG?w=753&h=500");
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  .zhuce{
    width: 70%;
    color: #000;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    font-size: 16px;
  }
  .van-cell-group{
    background: none;
    .van-field{
      margin-bottom: 20px;
      border-radius: 8px;
      background: rgba($color: #e7edfd, $alpha: 0.6);
    }
    input{
      color: #fff;
    }
  }
}
</style>
